package net.entelijan.cobean.data.literature.persistence;

import java.util.ArrayList;
import java.util.List;

public abstract class IterableClauseMapping<T> implements ClauseMapping {

	private Iterable<T> iterable;

	public IterableClauseMapping(Iterable<T> iterable) {
		super();
		this.iterable = iterable;
	}

	@Override
	public List<?> getClauseItems() {
		ArrayList<Object> re = new ArrayList<Object>();
		if (this.iterable != null) {
			for (T elem : this.iterable) {
				Object mapped = map(elem);
				if (mapped != null) {
					re.add(mapped);
				}
			}
		}
		return re;
	}

	protected abstract Object map(T elem);

}
